package crudfx.field;
import javafx.scene.*;
import javafx.scene.paint.*;
import javafx.scene.shape.*;
import javafx.ext.swing.*;
import javax.swing.*;
import crudfx.interop.*;
import crudfx.data.*;
import java.util.*;
import crudfx.container.*;
import crudfx.control.*;
import javax.swing.*;
import javax.swing.border.*;
import javax.swing.event.*;
import java.awt.event.*;
import javax.swing.plaf.basic.*;
import javax.swing.plaf.*;

/**
 * @profile desktop
 * @author Sergey Surikov
 */
public class ArtListField extends UIComponent{
    public var text:String on replace { };
    public var values:String[] on replace {
        };
    public var color:Color=Color.web("#000000");
    public var selectedColor:Color=Color.web("#000000");
    public var selectedBackground:Color=Color.web("#000000");
    public-init var bold:Boolean=false;
    public-init var italic:Boolean=false;
    public-init var serifs:Boolean=false;
    public-init var monospaced:Boolean=false;
    public-init var size:Number=9;
    public var icon:javax.swing.Icon;
    public var rollover:javax.swing.Icon;
    public var popupX:Number;
    public var popupY:Number;
    public var popupW:Number;
    public var popupBackground:Color;
    public var popupBorder:Color;
    var popup:PopupDialog;
    var rows:Rows;
    override public function getJComponent():JComponent{
        var g:JamRight=JamRight{
            content:ArtLabel{
                text:bind text
                size:size
                bold:bold
                italic:italic
                serifs:serifs
                monospaced:monospaced
                color:bind color
                }
            jam:ArtButton{
                icon:bind icon
                rollover:bind rollover
                action:function(){
                    var w:Number=g.getJComponent().getSize().width;
                    var y:Number=g.getJComponent().getSize().height;
                    popup.y=y+popupY;
                    popup.x=popupX;
                    popup.width=w+popupW;
                    rows=Rows{
                        content:for(i:String in values)Spectator{
                            var la:ArtLabel
                            var fi:Fill
                            content:fi=Fill{
                                color:Color.web("#000000",0.01)
                                content:la=ArtLabel{
                                    text:i
                                    size:size
                                    bold:bold
                                    italic:italic
                                    serifs:serifs
                                    monospaced:monospaced
                                    color:color
                                    }
                                }
                            clicked:function(e:MouseEvent):Void{
                                text=i;
                                popup.hide();
                                }
                            entered:function(e:MouseEvent):Void{
                                la.color=selectedColor;
                                fi.color=selectedBackground;
                                }
                            exited:function(e:MouseEvent):Void{
                                la.color=color;
                                fi.color=Color.web("#000000",0.01)
                                }
                            }
                        };
                    popup.height=popup.content.getJComponent().getPreferredSize().height;
                    popup.show();
                    }
                }
            };
        popup=crudfx.container.PopupDialog{
            x:0
            y:0
            width:100
            height:200
            parent:g
            content:Edge{
                color:popupBorder
                thickness:1
                content:Fill{
                    color:popupBackground
                    content:Margin{
                        left:4 top:2 right:2 bottom:2
                        content:bind rows
                        }
                    }
                }
            };
        return g.getJComponent();
        }
    override public function highlight(s:String):Boolean{
        return false;
        }
    override public function gather():DataTree{
        var me:DataTree=DataTree{ name:"ArtListField" };
        //me.node("text").asString("").value=text;
        return me;
        }
    }
